﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GTA.UserControls
{
    public partial class UcNumberText : UserControl
    {
        #region Start Control
        public UcNumberText()
        {
            InitializeComponent();
        }
        #endregion

        #region Properties
        public override String Text
        {
            get { return txtNumber.Text; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    Int32 vl = Int32.MinValue;
                    if (!Int32.TryParse(value, out vl))
                        throw new InvalidOperationException("Invalid type of value! This field accept only numbers.");
                }
                txtNumber.Text = value;
            }
        }
        [Browsable(true),
        Description("Set the MaxLength of the control"),
        Category("Behavior"),
        DefaultValue(32767)]
        public Int32 MaxLength
        {
            get { return txtNumber.MaxLength; }
            set { txtNumber.MaxLength = value; }
        }
        #endregion

        #region Events
        private void txtNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Convert.ToInt32(e.KeyChar) != (int)Keys.Back &&
                !Char.IsNumber(e.KeyChar))
                e.Handled = true;
        }
        #endregion
    }
}
